import request from "@/utils/request";
import type {
  ComputerTypeForm,
  ComputerQuery,
  AssetComputerPageVO,
} from "./model";
class ComputerAPI {
  /**
   * 新增电脑类型
   *
   * @param data
   */
  static addComputer(data: ComputerTypeForm) {
    return request({
      url: "/api/v1/asset/computer",
      method: "post",
      data: data,
    });
  }
  /**
   * 获取用户分页列表
   *
   * @param queryParams
   */
  static getPage(queryParams: ComputerQuery) {
    return request<any, PageResult<AssetComputerPageVO[]>>({
      url: "/api/v1/asset/computer/page",
      method: "get",
      params: queryParams,
    });
  }

  /**
   * 获取电脑表单数据
   *
   * @param id
   */
  static getComputerForm(id: number) {
    return request<any, ComputerTypeForm>({
      url: "/api/v1/asset/computer/" + id + "/form",
      method: "get",
    });
  }

  /**
   * 修改电脑
   *
   * @param id
   * @param data
   */
  static updateComputer(id: number, data: ComputerTypeForm) {
    return request({
      url: "/api/v1/asset/computer/" + id,
      method: "put",
      data: data,
    });
  }

  /**
   * 删除电脑
   *
   * @param ids 字典项ID，多个以英文逗号(,)分割
   */
  static deleteComputerByIds(ids: string) {
    return request({
      url: "/api/v1/asset/computer/" + ids,
      method: "delete",
    });
  }

  /**
   * 下载用户导入模板
   *
   * @returns
   */
  static downloadTemplate() {
    return request({
      url: "/api/v1/asset/computer/template",
      method: "get",
      responseType: "arraybuffer",
    });
  }

  /**
   * 导入电脑
   *
   * @param file
   */
  static import(file: File) {
    const formData = new FormData();
    formData.append("file", file);
    return request({
      url: "/api/v1/asset/computer/import",
      method: "post",
      data: formData,
      headers: {
        "Content-Type": "multipart/form-data",
      },
    });
  }

  /**
   * 导出电脑
   *
   * @param queryParams
   * @returns
   */
  static export(queryParams: ComputerQuery) {
    return request({
      url: "/api/v1/asset/computer/export",
      method: "get",
      params: queryParams,
      responseType: "arraybuffer",
    });
  }
}

export default ComputerAPI;
